<template>
  <div class="container">
    <div v-show="!showDetail">
      <!-- 搜索 -->
      <table>
        <tr>
          <th>
            <span>校区：</span>
            <el-button
              @click="openCampusList = true"
              type="text"
              style="width: 250px; text-align: left;"
            >
              <span v-if="campusSelect">{{campusSelect.name}}</span>
              <span v-else>未选择</span>
            </el-button>
          </th>
          <th>
            <span>功能区：</span>
            <el-button
              @click="openAreaList = true"
              type="text"
              style="width: 250px; text-align: left;"
            >
              <span v-if="areaSelect">{{areaSelect.name}}</span>
              <span v-else>未选择</span>
            </el-button>
          </th>
          <th>
            <el-button type="primary" icon="el-icon-search" @click="searchArea">搜索</el-button>
          </th>
        </tr>
      </table>
      <!-- 校区筛选 -->
      <el-dialog title="选择校区" :visible.sync="openCampusList">
        <el-input placeholder="请输入关键字" v-model="campusKeyword">
          <template slot="prepend">校区名</template>
          <el-button slot="append" icon="el-icon-search" @click="getCampusByKeyword"></el-button>
        </el-input>
        <br />
        <br />
        <el-radio-group v-model="campusSelect">
          <el-radio
            v-for="(campus, index) in campusList"
            :key="'campus' + index"
            :label="campus"
          >{{ campus.name }}</el-radio>
        </el-radio-group>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="campusSelect = ''">清 空</el-button>
          <el-button type="primary" @click="openCampusList = false">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 功能区筛选 -->
      <el-dialog title="选择功能区" :visible.sync="openAreaList">
        <el-input placeholder="请输入关键字" v-model="areaKeyword">
          <template slot="prepend">功能区名</template>
          <el-button slot="append" icon="el-icon-search" @click="getAreaByKeyword"></el-button>
        </el-input>
        <br />
        <br />
        <el-radio-group v-model="areaSelect">
          <el-radio
            v-for="(area, index) in areaList"
            :key="'area' + index"
            :label="area"
          >{{ area.name }}</el-radio>
        </el-radio-group>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="areaSelect = ''">清 空</el-button>
          <el-button type="primary" @click="openAreaList = false">确 定</el-button>
        </div>
      </el-dialog>
      <hr />
      <!-- 功能区列表 -->
      <el-table
        :data="allAreaList.slice((currentPage-1)*pagesize,currentPage*pagesize)"
        stripe
        border
        @row-click="rowClick"
      >
        <el-table-column prop="id" label="功能区编号" />
        <el-table-column prop="name" label="功能区名称" />
        <el-table-column prop="school_name" label="所在校区名称" />
        <el-table-column prop="english_name" label="功能区英文名" />
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableTotal"
        style="margin-left: 30%;"
      ></el-pagination>
    </div>
    <!-- 详情显示 -->
    <div v-show="showDetail">
      <areaDetails :areaDetails="areaDetails" @closeDetailDialog="closeDetailDialog" />
    </div>
  </div>
</template>

<script>
import areaDetails from "@/views/education-collegeField/area/details";
export default {
  name: "Area",
  data() {
    return {
      tableTotal: 0,
      currentPage: 1,
      pagesize: 10,
      showDetail: false, //功能区详情显示
      areaDetails: {}, //某一行功能区的详情
      allAreaList: [], //所有功能区列表

      openCampusList: false, //校区筛选对话框显示
      campusSelect: "", //选择的校区
      campusKeyword: "", //关键词搜索校区
      campusList: [], //校区列表

      openAreaList: false, //功能区筛选对话框显示
      areaSelect: "", //选择的功能区
      areaKeyword: "", //关键词搜索功能区
      areaList: [], //功能区列表
    };
  },
  components: {
    areaDetails,
  },
  created() {
    //获取所有功能区列表
    this.getAllAreaList();
    //获取功能区列表
    this.getAreaList();
    //获取校区列表
    this.getCampusList();
  },
  methods: {
    //获取所有功能区列表
    getAllAreaList() {
      this.allAreaList = [
        {
          id: "12345",
          college_id: "123456789",
          school_id: "12345678",
          name: "第一教学楼",
          english_name: "The first teaching building",
          telephone: "18023649352",
          discription: "暂无描述",
          create_time: "2020-6-12 20:30:00",
          by_who: "（userid）",
        },
        {
          id: "12346",
          college_id: "123456789",
          school_id: "12345678",
          name: "第二教学楼",
          english_name: "The second teaching building",
          telephone: "18023649352",
          discription: "暂无描述",
          create_time: "2020-6-12 20:30:00",
          by_who: "（userid）",
        },
      ];
    },

    //获取功能区列表
    getAreaList() {
      this.areaList = [
        { id: "1", name: "第一教学楼" },
        { id: "2", name: "第二教学楼" },
        { id: "3", name: "第三教学楼" },
        { id: "4", name: "美术大楼" },
        { id: "5", name: "中巴科技园" },
      ];
    },

    //获取校区列表
    getCampusList() {
      this.campusList = [
        { id: "1", name: "主校区" },
        { id: "2", name: "星湖校区" },
      ];
    },

    //确定选择的校区
    campusSelected() {},

    //确定选择的功能区
    areaSelected() {},

    //条件搜索
    searchArea() {},

    //关键词搜索校区
    getCampusByKeyword() {},

    //关键词搜索功能区
    getAreaByKeyword() {},

    //点击某一行，显示功能区详情
    rowClick(val) {
      this.areaDetails = val;
      this.showDetail = true;
    },

    //详情组件传来的数据
    closeDetailDialog(val) {
      this.showDetail = val;
    },

    // 换页
    handleSizeChange: function (size) {
      this.pagesize = size;
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
    },
  },
};
</script>

<style scoped>
.container {
  width: 80%;
  max-width: 100%;
  margin: 20px auto;
}
span {
  font-weight: 500;
}
th {
  text-align: left;
}
</style>
